/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/misc/vectorutils.h,v 1.6 2003/11/21 12:39:24 itsme Exp $
 *
 *
 */


#ifndef __VECTORUTILS_H_


#include <windows.h>
#include <vector>
#include <string>
#include <limits>

// used for easy instantiation of arrays
template<class T> std::vector<T> MakeVector(int n, ...)
{
    std::vector<T> v;

    va_list ap;
    va_start(ap, n);
    while (n--)
        v.push_back(va_arg(ap, T));
    va_end(ap);

    return v;
}

#ifdef _WIN32_WCE
typedef std::vector<BYTE> ByteVector;
#else
#include <SafeByteVector.h>
#endif

typedef std::vector<WORD> WordVector;
typedef std::vector<DWORD> DwordVector;

typedef std::vector<int> IntVector;

#define vectorptr(v)  (&(v)[0])
#define iteratorptr(v)  (&(*v))

void BV_AppendByte(ByteVector& v, BYTE b);
void BV_AppendWord(ByteVector& v, WORD b);
void BV_AppendDword(ByteVector& v, DWORD b);
void BV_AppendNetWord(ByteVector& v, WORD b);
void BV_AppendNetDword(ByteVector& v, DWORD b);
void BV_AppendVector(ByteVector& v1, const ByteVector& v2);
void BV_AppendString(ByteVector& v, const std::string& s);
void BV_AppendWString(ByteVector& v, const std::wstring& s);
void BV_AppendRange(ByteVector& v, const ByteVector::const_iterator& begin, const ByteVector::const_iterator& end);

BYTE BV_GetByte(ByteVector::const_iterator &i);
WORD BV_GetWord(ByteVector::const_iterator &i);
DWORD BV_GetDword(ByteVector::const_iterator &i);
std::string* BV_GetString(ByteVector::const_iterator &i, int len);

// bufpack/bufunpack are vaguely based on perl's pack/unpack
void vbufpack(ByteVector& buf, const char *fmt, va_list ap);
void bufpack(ByteVector& buf, const char *fmt, ...);
DwordVector bufunpack(const ByteVector& buf, const char *fmt);

#define __VECTORUTILS_H_
#endif
